<?php
/**
 * Created by PhpStorm.
 * User: Administrator
 * Date: 2017/12/9 0009
 * Time: 12:58
 */

namespace common\models;


use yii\db\ActiveRecord;

use yii\data\ActiveDataProvider;

class Contact extends ActiveRecord{

    public $verifyCode;


    public static function tableName()
    {
        return 'contact';
    }
    public function rules()
    {
        return [
            // name, email, subject and body are required
            ['id', 'integer'],
            ['uid', 'integer'],

        ];
    }
//    public function sendEmail($email)
//    {
//        return Yii::$app->mailer->compose()
//            ->setTo($email)
//            ->setFrom([$this->email => $this->name])
//            ->setSubject($this->subject)
//            ->setTextBody($this->body)
//            ->send();
//    }
    public function attributeLabels()
    {
        return [
            'id'=>'id',

            'subject'=>'内容',

            'createtime'=>'发布时间',

        ];
    }
    //查询
    public function search($params)
    {
        //首先我们先获取一个ActiveQuery
        $query = self::find();
        //然后创建一个ActiveDataProvider对象
        $provider = new ActiveDataProvider([
            //为ActiveDataProvider对象提供一个查询对象
            'query' => $query,
            //设置分页参数
            'pagination' => [
                //分页大小
                'pageSize' => 5,
                //设置地址栏当前页数参数名
                'pageParam' => 'p',
                //设置地址栏分页大小参数名
                'pageSizeParam' => 'pageSize',
            ],
            //设置排序
            'sort' => [
                //默认排序方式
                'defaultOrder' => [
                    'id' => SORT_DESC,
                ],

            ],
        ]);

        //如果验证没通过，直接返回
        if (!($this->load($params) && $this->validate())) {
            return $provider;
        }

        //增加过滤条件
        $query->andFilterWhere(['id' => $this->id]);
        $query->andFilterWhere(['uid' => $this->uid]);

        return $provider;
    }
}